package uniandes.dermatologia.models;

import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;

import uniandes.dermatologia.singleton.DermatologiaUniandesApp;

public class Anamnesis {

	public enum Gender {
		men, women
	}

	public enum Phototypes {
		PHOTOTYPE_I, PHOTOTYPE_II, PHOTOTYPE_III, PHOTOTYPE_IV, PHOTOTYPE_V, PHOTOTYPE_VI
	}

	public enum Age {
		adult, child, fetal, infant, neonate, pediatric
	}

	private Gender gender;

	private Phototypes phototypes;

	private Date birthDate;
	
	private Age age;

	public Anamnesis() {

	}

	public Anamnesis(Gender nGender, Phototypes nPhototypes, Date nBirthDate) {
		gender = nGender;
		phototypes = nPhototypes;
		birthDate = nBirthDate;
	}

	public Gender getGender() {
		return gender;
	}

	public void setGender(Gender gender) {
		this.gender = gender;
	}

	public Phototypes getPhototypes() {
		return phototypes;
	}

	public void setPhototypes(Phototypes phototypes) {
		this.phototypes = phototypes;
	}

	public Date getBirthDate() {
		return birthDate;
	}

	public void setBirthDate(Date birthDate) {
		this.birthDate = birthDate;
	}
	
	public Age getAge() {
		return age;
	}

	public void setAge(Age age) {
		this.age = age;
	}
	
	public String getGenderString()
	{
		String genderString = gender == Gender.men? "M" : "F";		
		return genderString;
	}
	
	public void setGenderFromString(String genderString)
	{
		gender = genderString.equals("M")? Gender.men : Gender.women;
	}
	
	public String getPhototypeString()
	{
		String phototypeString = "I";
		
		switch(phototypes)
		{
			case PHOTOTYPE_I:
				phototypeString = "I";
				break;
			case PHOTOTYPE_II:
				phototypeString = "II";
				break;
			case PHOTOTYPE_III:
				phototypeString = "III";
				break;
			case PHOTOTYPE_IV:
				phototypeString = "IV";
				break;
			case PHOTOTYPE_V:
				phototypeString = "V";
				break;
			case PHOTOTYPE_VI:
				phototypeString = "VI";
				break;
		}
		return phototypeString;
	}
	
	public void setPhototypeFromString(String phototypeString)
	{
		if(phototypeString.equals("I"))
		{
			phototypes = Phototypes.PHOTOTYPE_I;
		}
		else if(phototypeString.equals("II"))
		{
			phototypes = Phototypes.PHOTOTYPE_II;
		}
		else if(phototypeString.equals("III"))
		{
			phototypes = Phototypes.PHOTOTYPE_III;
		}
		else if(phototypeString.equals("IV"))
		{
			phototypes = Phototypes.PHOTOTYPE_IV;
		}
		else if(phototypeString.equals("V"))
		{
			phototypes = Phototypes.PHOTOTYPE_V;
		}
		else
		{
			phototypes = Phototypes.PHOTOTYPE_VI;
		}
	}
	
	//adult, child, fetal, infant, neonate, pediatric
	public String getAgeString()
	{
		String ageString = "adult";
		switch(age)
		{
			case adult:
				ageString = "adult";
				break;
			case child:
				ageString = "child";
				break;
			case fetal:
				ageString = "fetal";
				break;
			case infant:
				ageString = "infant";
				break;
			case neonate:
				ageString = "neonate";
				break;
			case pediatric:
				ageString = "pediatric";
				break;
		}
		return ageString;
	}
	
	public void setAgeFromString(String ageString)
	{
		if(ageString.equals("adult"))
		{
			age = Age.adult;
		}
		else if(ageString.equals("child"))
		{
			age = Age.child;
		}
		else if(ageString.equals("fetal"))
		{
			age = Age.fetal;
		}
		else if(ageString.equals("infant"))
		{
			age = Age.infant;
		}
		else if(ageString.equals("neonate"))
		{
			age = Age.neonate;
		}
		else if(ageString.equals("pediatric"))
		{
			age = Age.pediatric;
		}
	}
	
	public String getBirthDateString()
	{
		DateFormat df = new SimpleDateFormat(DermatologiaUniandesApp.DATE_PATTERN, Locale.US);
		return df.format(birthDate);
	}
	
	public void setBirthDateFromString(String birthDateString) throws ParseException
	{
		try {
			birthDate = new SimpleDateFormat(DermatologiaUniandesApp.DATE_PATTERN, Locale.US).parse(birthDateString);
			
		} catch (ParseException e) {
			e.printStackTrace();
		}
	}
}
